package liurong.driver.proxy;

import java.lang.reflect.Proxy;

import org.junit.Test;

import liurong.driver.proxy.cglib.CglibHandler;
import liurong.driver.proxy.jdk.JdkProxyHandler;
import net.sf.cglib.core.DebuggingClassWriter;
import net.sf.cglib.proxy.Enhancer;

public class BussinessServiceTest {

	@Test
	public void testJdk() {
		BussinessService bussinessService = new BussinessServiceImpl();

		BussinessService bussinessService2 = (BussinessService) Proxy.newProxyInstance(
				bussinessService.getClass().getClassLoader(), bussinessService.getClass().getInterfaces(),
				new JdkProxyHandler(bussinessService));

		bussinessService2.work();
	}

	@Test
	public void testCglib() {

		System.setProperty(DebuggingClassWriter.DEBUG_LOCATION_PROPERTY, "D:\\java\\java_workapace");

		Enhancer enhancer = new Enhancer();
		enhancer.setSuperclass(BussinessServiceImpl.class);
		enhancer.setCallback(new CglibHandler());

		BussinessServiceImpl create = (BussinessServiceImpl) enhancer.create();
		create.work();
	}
}
